// @Author EthanScriptOn
// @Desc
package util

import (
	"math/rand"
	"strings"
	"time"
)

// GetRandomIndex Get a random number
func GetRandomIndex(indexRange int) int {
	if indexRange == 0 {
		return 0
	}
	nano := time.Now().UnixNano()
	rand.Seed(nano)
	return rand.Intn(indexRange + 1)
}

// GetPosition Get location information stack information
func GetPosition(skip int) string {
	currentName := GetMethodNameSkip(skip)
	stackPrintTrace := StackPrint()
	split := strings.Split(stackPrintTrace, "\n")
	for index, errStr := range split {
		if strings.Contains(errStr, currentName) {
			split = split[index+1:]
			break
		}
	}
	return strings.Join(split, "\n")
}
